﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using SystemDirectory.Common;
using SystemDirectory.Entity;

namespace SystemDirectory.DAO
{
    public class DAOPremise
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TestConnectionString2"].ToString());
        SqlCommand com;
        SqlDataAdapter adapt;
        DataTable dtResult;
        
        public DataTable Get(bool ShowInactive, Utilities.SearchType IsSearch)
        {

            if (con.State == ConnectionState.Closed)
            {
                con.Open();
            }

            switch (IsSearch)
            {
                case Utilities.SearchType.TypeAll:
                    {
                        if (ShowInactive)
                            com = new SqlCommand("SELECT * FROM NewPremise", con);
                        else
                            com = new SqlCommand("SELECT * FROM NewPremise WHERE IsActive = 'true'", con);
                        break;
                    }
                case Utilities.SearchType.Type09:
                    {
                        if (ShowInactive)
                        {
                            com = new SqlCommand("SELECT * FROM NewPremise WHERE LocationName LIKE '0%' OR LocationName LIKE '1%' OR LocationName LIKE '2%' OR LocationName LIKE '3%' OR LocationName LIKE '4%'OR LocationName LIKE '5%' OR LocationName LIKE '6%' OR LocationName LIKE '7%' OR LocationName LIKE '9%'", con);
                        }
                        else
                        {
                            com = new SqlCommand("SELECT * FROM NewPremise WHERE (LocationName LIKE '0%' OR LocationName LIKE '1%' OR LocationName LIKE '2%' OR LocationName LIKE '3%' OR LocationName LIKE '4%'OR LocationName LIKE '5%' OR LocationName LIKE '6%' OR LocationName LIKE '7%' OR LocationName LIKE '9%') AND IsActive = 'true'", con);
                        }
                        break;
                    }

                case Utilities.SearchType.TypeAE:
                    {
                        if (ShowInactive)
                        {
                            com = new SqlCommand("SELECT * FROM NewPremise WHERE LocationName LIKE 'A%' OR LocationName LIKE 'B%' OR LocationName LIKE 'C%' OR LocationName LIKE 'D%' OR LocationName LIKE 'E%'", con);
                        }
                        else
                        {
                            com = new SqlCommand("SELECT * FROM NewPremise WHERE ( LocationName LIKE 'A%' OR LocationName LIKE 'B%' OR LocationName LIKE 'C%' OR LocationName LIKE 'D%' OR LocationName LIKE 'E%') AND IsActive = 'true'", con);
                        }
                        break;
                    }
                case Utilities.SearchType.TypeFJ:
                    {
                        if (ShowInactive)
                        {
                            com = new SqlCommand("SELECT * FROM NewPremise WHERE LocationName LIKE 'F%' OR LocationName LIKE 'G%' OR LocationName LIKE 'H%' OR LocationName LIKE 'I%' OR LocationName LIKE 'J%'", con);
                        }
                        else
                        {
                            com = new SqlCommand("SELECT * FROM NewPremise WHERE ( LocationName LIKE 'F%' OR LocationName LIKE 'G%' OR LocationName LIKE 'H%' OR LocationName LIKE 'I%' OR LocationName LIKE 'J%') AND IsActive = 'true'", con);
                        }
                        break;
                    }
                case Utilities.SearchType.TypeKM:
                    if (ShowInactive)
                        {
                            com = new SqlCommand("SELECT * FROM NewPremise WHERE LocationName LIKE 'K%' OR LocationName LIKE 'L%' OR LocationName LIKE 'M%' OR LocationName LIKE 'N%'", con);
                        }
                        else
                        {
                            com = new SqlCommand("SELECT * FROM NewPremise WHERE (LocationName LIKE 'K%' OR LocationName LIKE 'L%' OR LocationName LIKE 'M%' OR LocationName LIKE 'N%') AND IsActive = 'true'", con);
                        }
                        break;
                case Utilities.SearchType.TypeOR:
                    if (ShowInactive)
                        {
                            com = new SqlCommand("SELECT * FROM NewPremise WHERE LocationName LIKE 'O%' OR LocationName LIKE 'P%' OR LocationName LIKE 'Q%' OR LocationName LIKE 'R%'", con);
                        }
                        else
                        {
                            com = new SqlCommand("SELECT * FROM NewPremise WHERE ( LocationName LIKE 'O%' OR LocationName LIKE 'P%' OR LocationName LIKE 'Q%' OR LocationName LIKE 'R%') AND IsActive = 'true'", con);
                        }
                        break;
                case Utilities.SearchType.TypeSV:
                    if (ShowInactive)
                        {
                            com = new SqlCommand("SELECT * FROM NewPremise WHERE LocationName LIKE 'S%' OR LocationName LIKE 'T%' OR LocationName LIKE 'U%' OR LocationName LIKE 'V%'", con);
                        }
                        else
                        {
                            com = new SqlCommand("SELECT * FROM NewPremise WHERE ( LocationName LIKE 'S%' OR LocationName LIKE 'T%' OR LocationName LIKE 'U%' OR LocationName LIKE 'V%') AND IsActive = 'true'", con);
                        }
                        break;
                case Utilities.SearchType.TypeWZ:
                    if (ShowInactive)
                        {
                            com = new SqlCommand("SELECT * FROM NewPremise WHERE LocationName LIKE 'W%' OR LocationName LIKE 'X%' OR LocationName LIKE 'Y%' OR LocationName LIKE 'Z%'", con);
                        }
                        else
                        {
                            com = new SqlCommand("SELECT * FROM NewPremise WHERE ( LocationName LIKE 'W%' OR LocationName LIKE 'X%' OR LocationName LIKE 'Y%' OR LocationName LIKE 'Z%') AND IsActive = 'true'", con);
                        }
                        break;

            }

            adapt = new SqlDataAdapter(com);
            dtResult = new DataTable();
            adapt.Fill(dtResult);
            return dtResult;

        }
        public int GetLastId()
        {
            SqlCommand com = new SqlCommand("SELECT TOP 1 * FROM NewPremise ORDER BY PremiseID DESC", con);             
            SqlDataAdapter adapt = new SqlDataAdapter(com);
            DataTable dtResult = new DataTable();
            adapt.Fill(dtResult);
            int lastId = Convert.ToInt32(dtResult.Rows[0]["PremiseID"].ToString());
            return lastId;
        }
        public bool AddPremise(Premise premiseIn)
        {
            if (con.State == ConnectionState.Closed)
            {
                con.Open();
            }
            SqlCommand com = new SqlCommand("INSERT INTO NewPremise( LocationName,AddressLine1,PostCode,IsActive,knowAs,locationOrg,locationStatus,locationDate,AddressLine2,AddressLine3,cityTown,country,nationCoutry,primaryLocation,locationMa,stNetCon,locationDes,phoneNum,faxNum,minNum,isShop,shopDate,specialistShop)VALUES (@LocationName, @AddressLine1,@PostCode, @IsActive, @knowAs, @locationOrg, @locationStatus,@locationDate, @AddressLine2, @AddressLine3, @cityTown,@country, @nationCoutry ,@primaryLocation, @locationMa,@stNetCon, @locationDes, @phoneNum, @faxNum, @minNum, @isShop,@shopDate,@specialistShop)", con); ;// @specialistShop, @mediaContact, @mediaContactName, @LocalDemNotes, @cateringFac, @cateringCon, @cateringType, @isNet, @clientItFac, @clientItFacDe, @roomAvai , @ovlunOpp, @travelDe, @travelNeBus, @travelNeAi, @travelNeRai, @hostVisit, @hostContact, @visitOn, @visitSpace, @visitAlt, @roonRate, @bbRate, @dbbRate, @ddRate, @hrRate, @teaCoff, @lunch, @noRoom, @metRoom, @codding, @neRoom, @bbNeRate, @dbbNeRate, @hrNeRate, @lastNeRoom, @reNeOn, @PreStatus, @comment)", con);//)", con);
                                                            
           
            com.Parameters.Add("@LocationName", SqlDbType.NVarChar, 255);
            com.Parameters["@LocationName"].Value = premiseIn.locationName;

            com.Parameters.Add("@AddressLine1", SqlDbType.NVarChar, 255);
            com.Parameters["@AddressLine1"].Value = premiseIn.address1;

            com.Parameters.Add("@PostCode", SqlDbType.NVarChar, 255);            
            com.Parameters["@PostCode"].Value = premiseIn.postcode;

             com.Parameters.Add("@IsActive", SqlDbType.Bit);
             com.Parameters["@IsActive"].Value = premiseIn.isActive;
             
             com.Parameters.Add("@knowAs", SqlDbType.NVarChar, 255);
             com.Parameters["@knowAs"].Value = premiseIn.knowAs;

             com.Parameters.Add("@locationOrg", SqlDbType.NVarChar, 255);
             com.Parameters["@locationOrg"].Value = premiseIn.locationOrg;

             com.Parameters.Add("@locationStatus", SqlDbType.NVarChar, 255);
             com.Parameters["@locationStatus"].Value = premiseIn.locationStatus;

             com.Parameters.Add("@locationDate", SqlDbType.Date);
             com.Parameters["@locationDate"].Value = premiseIn.locationDate;

             com.Parameters.Add("@AddressLine2", SqlDbType.NVarChar, 255);
             com.Parameters["@AddressLine2"].Value = premiseIn.address2;

             com.Parameters.Add("@AddressLine3", SqlDbType.NVarChar, 255);
             com.Parameters["@AddressLine3"].Value = premiseIn.address3;

             com.Parameters.Add("@cityTown", SqlDbType.NVarChar, 255);
             com.Parameters["@cityTown"].Value = premiseIn.ctyTown;

             com.Parameters.Add("@country", SqlDbType.NVarChar, 255);
             com.Parameters["@country"].Value = premiseIn.country;

             com.Parameters.Add("@nationCoutry", SqlDbType.NVarChar, 255);
             com.Parameters["@nationCoutry"].Value = premiseIn.nationContry;       
      
             com.Parameters.Add("@primaryLocation", SqlDbType.Bit);
             com.Parameters["@primaryLocation"].Value = premiseIn.primary;

             com.Parameters.Add("@locationMa", SqlDbType.Bit);
             com.Parameters["@locationMa"].Value = premiseIn.locationMa;

             com.Parameters.Add("@stNetCon", SqlDbType.Bit);
             com.Parameters["@stNetCon"].Value = premiseIn.stNetCon;

             com.Parameters.Add("@locationDes", SqlDbType.NVarChar, 255);
             com.Parameters["@locationDes"].Value = premiseIn.locatonDes;

             com.Parameters.Add("@phoneNum", SqlDbType.NVarChar, 255);
             com.Parameters["@phoneNum"].Value = premiseIn.phoneNum;

             com.Parameters.Add("@faxNum", SqlDbType.NVarChar, 255);
             com.Parameters["@faxNum"].Value = premiseIn.faxNum;

             com.Parameters.Add("@minNum", SqlDbType.NVarChar, 255);
            com.Parameters["@minNum"].Value = premiseIn.minNum;

             com.Parameters.Add("@isShop", SqlDbType.Bit);
             com.Parameters["@isShop"].Value = premiseIn.isShop;

             com.Parameters.Add("@shopDate", SqlDbType.Date);
             com.Parameters["@shopDate"].Value = premiseIn.shopDate;

             com.Parameters.Add("@specialistShop", SqlDbType.Bit);
             com.Parameters["@specialistShop"].Value = premiseIn.specialistDhop;

             //com.Parameters.Add("@mediaContact", SqlDbType.Bit);
             //com.Parameters["@mediaContact"].Value = premiseIn.mediaContact;

             //com.Parameters.Add("@mediaContactName", SqlDbType.NVarChar, 255);
             //com.Parameters["@mediaContactName"].Value = premiseIn.mediaContactName;

             //com.Parameters.Add("@LocalDemNotes", SqlDbType.NVarChar, 255);
             //com.Parameters["@LocalDemNotes"].Value = premiseIn.localDemNote;

             //com.Parameters.Add("@cateringFac", SqlDbType.Bit);
             //com.Parameters["@cateringFac"].Value = premiseIn.cateringFac;

             //com.Parameters.Add("@cateringCon", SqlDbType.NVarChar, 255);
             //com.Parameters["@cateringCon"].Value = premiseIn.cateringCon;

             //com.Parameters.Add("@cateringType", SqlDbType.NVarChar, 255);
             //com.Parameters["@cateringType"].Value = premiseIn.cateringType;

             //com.Parameters.Add("@isNet", SqlDbType.NVarChar, 255);
             //com.Parameters["@isNet"].Value = premiseIn.isNet;

             //com.Parameters.Add("@clientItFac", SqlDbType.Bit);
             //com.Parameters["@clientItFac"].Value = premiseIn.clientItfac;

             //com.Parameters.Add("@clientItFacDe", SqlDbType.NVarChar, 255);
             //com.Parameters["@clientItFacDe"].Value = premiseIn.clientItDe;

             //com.Parameters.Add("@roomAvai", SqlDbType.Bit);
             //com.Parameters["@roomAvai"].Value = premiseIn.roomAvai;

             //com.Parameters.Add("@ovlunOpp", SqlDbType.Bit);
             //com.Parameters["@ovlunOpp"].Value = premiseIn.volunOpp;

             //com.Parameters.Add("@travelDe", SqlDbType.NVarChar, 255);
             //com.Parameters["@travelDe"].Value = premiseIn.travelDatail;

             //com.Parameters.Add("@travelNeBus", SqlDbType.NVarChar, 255);
             //com.Parameters["@travelNeBus"].Value = premiseIn.travelNeaBus;

             //com.Parameters.Add("@travelNeAi", SqlDbType.NVarChar, 255);
             //com.Parameters["@travelNeAi"].Value = premiseIn.travelNeaAil;

             //com.Parameters.Add("@travelNeRai", SqlDbType.NVarChar, 255);
             //com.Parameters["@travelNeRai"].Value = premiseIn.travalNeaRail;

             //com.Parameters.Add("@hostVisit", SqlDbType.Bit);
             //com.Parameters["@hostVisit"].Value = premiseIn.hostViset;

             //com.Parameters.Add("@hostContact", SqlDbType.NVarChar, 255);
             //com.Parameters["@hostContact"].Value = premiseIn.hostContact;

             //com.Parameters.Add("@visitOn", SqlDbType.Bit);
             //com.Parameters["@visitOn"].Value = premiseIn.visitOnsite;

             //com.Parameters.Add("@visitSpace", SqlDbType.NVarChar, 255);
             //com.Parameters["@visitSpace"].Value = premiseIn.visitSpace;

             //com.Parameters.Add("@visitAlt", SqlDbType.NVarChar, 255);
             //com.Parameters["@visitAlt"].Value = premiseIn.visitAlte;

             //com.Parameters.Add("@roonRate", SqlDbType.NVarChar, 255);
             //com.Parameters["@roonRate"].Value = premiseIn.roomRate;

             //com.Parameters.Add("@bbRate", SqlDbType.NVarChar, 255);
             //com.Parameters["@bbRate"].Value = premiseIn.bbRate;

             //com.Parameters.Add("@dbbRate", SqlDbType.NVarChar, 255);
             //com.Parameters["@dbbRate"].Value = premiseIn.dbbRate;

             //com.Parameters.Add("@ddRate", SqlDbType.NVarChar, 255);
             //com.Parameters["@ddRate"].Value = premiseIn.ddRate;

             //com.Parameters.Add("@hrRate", SqlDbType.NVarChar, 255);
             //com.Parameters["@hrRate"].Value = premiseIn.hrRate;

             //com.Parameters.Add("@teaCoff", SqlDbType.NVarChar, 255);
             //com.Parameters["@teaCoff"].Value = premiseIn.teaCof;

             //com.Parameters.Add("@lunch", SqlDbType.Bit);
             //com.Parameters["@lunch"].Value = premiseIn.luch;

             //com.Parameters.Add("@noRoom", SqlDbType.NVarChar, 255);
             //com.Parameters["@noRoom"].Value = premiseIn.noRoom;

             //com.Parameters.Add("@metRoom", SqlDbType.NVarChar, 255);
             //com.Parameters["@metRoom"].Value = premiseIn.metRoom;

             //com.Parameters.Add("@codding", SqlDbType.NVarChar, 255);
             //com.Parameters["@codding"].Value = premiseIn.coding;

             //com.Parameters.Add("@neRoom", SqlDbType.NVarChar, 255);
             //com.Parameters["@neRoom"].Value = premiseIn.neRoom;

             //com.Parameters.Add("@bbNeRate", SqlDbType.NVarChar, 255);
             //com.Parameters["@bbNeRate"].Value = premiseIn.bbNeRoom;

             //com.Parameters.Add("@dbbNeRate", SqlDbType.NVarChar, 255);
             //com.Parameters["@dbbNeRate"].Value = premiseIn.dbbNeRoom;

             //com.Parameters.Add("@hrNeRate", SqlDbType.NVarChar, 255);
             //com.Parameters["@hrNeRate"].Value = premiseIn.hrNeRoom;

             //com.Parameters.Add("@lastNeRoom", SqlDbType.Date);
             //com.Parameters["@lastNeRoom"].Value = premiseIn.lastNeRoom;

             //com.Parameters.Add("@reNeOn", SqlDbType.Date);
             //com.Parameters["@reNeOn"].Value = premiseIn.reNeOn;

             //com.Parameters.Add("@PreStatus", SqlDbType.NVarChar, 255);
             //com.Parameters["@PreStatus"].Value = premiseIn.preStatus;

             //com.Parameters.Add("@comment", SqlDbType.NVarChar, 255);
             //com.Parameters["@comment"].Value = premiseIn.commen;

            return Convert.ToBoolean(com.ExecuteNonQuery());
             
        }
        public Premise GetById(int id)
        {
            SqlCommand com = new SqlCommand("SELECT * FROM NewPremise WHERE PremiseID = @id", con);
            com.Parameters.Add("@id", SqlDbType.Int);
            com.Parameters["@id"].Value = id;
            SqlDataAdapter adapt = new SqlDataAdapter(com);
            DataTable dtResult = new DataTable();
            adapt.Fill(dtResult);
            Premise premiseIn = new Premise();
            premiseIn.locationName = dtResult.Rows[0]["LocationName"].ToString();
            premiseIn.address1 = dtResult.Rows[0]["AddressLine1"].ToString();
            premiseIn.postcode = dtResult.Rows[0]["PostCode"].ToString();
            premiseIn.isActive = Convert.ToBoolean(dtResult.Rows[0]["IsActive"].ToString());
            premiseIn.knowAs = dtResult.Rows[0]["knowAs"].ToString();
            premiseIn.locationOrg = dtResult.Rows[0]["locationOrg"].ToString();
            premiseIn.locationStatus = dtResult.Rows[0]["locationStatus"].ToString();
            premiseIn.locationDate = dtResult.Rows[0]["locationDate"].ToString();
            premiseIn.address2 = dtResult.Rows[0]["AddressLine2"].ToString();
            premiseIn.address3=dtResult.Rows[0]["AddressLine3"].ToString();
            premiseIn.ctyTown = dtResult.Rows[0]["cityTown"].ToString();
            premiseIn.country=dtResult.Rows[0]["country"].ToString();
            premiseIn.nationContry = dtResult.Rows[0]["nationCoutry"].ToString();
            premiseIn.primary = true;//thu du lieu
            //premiseIn.primary = Convert.ToBoolean(dtResult.Rows[0]["primaryLocation"].ToString());
            premiseIn.locationMa = true;
            //premiseIn.locationMa = Convert.ToBoolean(dtResult.Rows[0]["locationMa"].ToString());
            premiseIn.stNetCon = false;
            //premiseIn.stNetCon = Convert.ToBoolean(dtResult.Rows[0]["stNetCon"].ToString());
            premiseIn.locatonDes = dtResult.Rows[0]["locationDes"].ToString();
            premiseIn.phoneNum = dtResult.Rows[0]["phoneNum"].ToString();
            premiseIn.faxNum=dtResult.Rows[0]["faxNum"].ToString();
            premiseIn.minNum = dtResult.Rows[0]["minNum"].ToString();
            premiseIn.isShop = false;
            //premiseIn.isShop = Convert.ToBoolean(dtResult.Rows[0]["isShop"].ToString());
            premiseIn.shopDate = dtResult.Rows[0]["shopDate"].ToString();
            //premiseIn.specialistDhop=Convert.ToBoolean(dtResult.Rows[0]["specialistShop"].ToString());
            premiseIn.specialistDhop = false;
            //premiseIn.mediaContact = Convert.ToBoolean(dtResult.Rows[0]["mediaContact"].ToString());
            //premiseIn.mediaContactName=dtResult.Rows[0]["mediaContactName"].ToString();
            //premiseIn.localDemNote=dtResult.Rows[0]["LocalDemNotes"].ToString();
            //premiseIn.cateringFac = Convert.ToBoolean(dtResult.Rows[0]["cateringFac"].ToString());
            //premiseIn.cateringCon = dtResult.Rows[0]["cateringCon"].ToString();
            //premiseIn.cateringType = dtResult.Rows[0]["cateringType"].ToString();
            //premiseIn.isNet=dtResult.Rows[0]["isNet"].ToString();
            //premiseIn.clientItfac = Convert.ToBoolean(dtResult.Rows[0]["clientItFac"].ToString());
            //premiseIn.clientItDe=dtResult.Rows[0]["clientItFacDe"].ToString();
            //premiseIn.roomAvai = Convert.ToBoolean(dtResult.Rows[0]["roomAvai"].ToString());
            //premiseIn.volunOpp = Convert.ToBoolean(dtResult.Rows[0]["ovlunOpp"].ToString());
            //premiseIn.travelDatail = dtResult.Rows[0]["travelDe"].ToString();
            //premiseIn.travelNeaBus = dtResult.Rows[0]["travelNeBus"].ToString();
            //premiseIn.travelNeaAil=dtResult.Rows[0]["travelNeAi"].ToString();
            //premiseIn.travalNeaRail = dtResult.Rows[0]["travelNeRai"].ToString();
            //premiseIn.hostViset = Convert.ToBoolean(dtResult.Rows[0]["hostVisit"].ToString());
            //premiseIn.hostContact = dtResult.Rows[0]["hostContact"].ToString();
            //premiseIn.visitOnsite=Convert.ToBoolean(dtResult.Rows[0]["visitOn"].ToString());
            //premiseIn.visitSpace = dtResult.Rows[0]["visitSpace"].ToString();
            //premiseIn.visitAlte=dtResult.Rows[0]["visitAlt"].ToString();
            //premiseIn.roomRate=dtResult.Rows[0]["roonRate"].ToString();
            //premiseIn.bbRate=dtResult.Rows[0]["bbRate"].ToString();
            //premiseIn.dbbRate = dtResult.Rows[0]["dbbRate"].ToString();
            //premiseIn.ddRate=dtResult.Rows[0]["ddRate"].ToString();
            //premiseIn.hrRate = dtResult.Rows[0]["hrRate"].ToString();
            //premiseIn.teaCof = dtResult.Rows[0]["teaCoff"].ToString();
            //premiseIn.luch = Convert.ToBoolean(dtResult.Rows[0]["lunch"].ToString());
            //premiseIn.noRoom=dtResult.Rows[0]["noRoom"].ToString();  
            //premiseIn.metRoom=dtResult.Rows[0]["metRoom"].ToString();
            //premiseIn.coding=dtResult.Rows[0]["codding"].ToString();
            //premiseIn.neRoom=dtResult.Rows[0]["neRoom"].ToString();
            //premiseIn.bbNeRoom = dtResult.Rows[0]["bbNeRate"].ToString();
            //premiseIn.dbbNeRoom = dtResult.Rows[0]["dbbNeRate"].ToString();
            //premiseIn.hrNeRoom = dtResult.Rows[0]["hrNeRate"].ToString();
            //premiseIn.lastNeRoom = dtResult.Rows[0]["lastNeRoom"].ToString();
            //premiseIn.reNeOn = dtResult.Rows[0]["reNeOn"].ToString();
            //premiseIn.preStatus = dtResult.Rows[0]["PreStatus"].ToString();
            //premiseIn.commen=dtResult.Rows[0]["comment"].ToString();
            return premiseIn;

        }
        public bool UpdatePremise(Premise premiseIn)
        {
             if (con.State == ConnectionState.Closed)
            {
                con.Open();
            }
             SqlCommand com = new SqlCommand("UPDATE NewPremise SET LocationName=@LocationName,AddressLine1=@AddressLine1,PostCode=@PostCode,IsActive=@IsActive,knowAs=@knowAs,locationOrg=@locationOrg,locationStatus=@locationStatus,locationDate=@locationDate,AddressLine2=@AddressLine2,AddressLine3=@AddressLine3,cityTown=@cityTown,country=@country,nationCoutry=@nationCoutry,primaryLocation=@primaryLocation,locationMa=@locationMa,stNetCon=@stNetCon,locationDes=@locationDes,phoneNum=@phoneNum,faxNum=@faxNum,minNum=@minNum,isShop=@isShop,shopDate=@shopDate,specialistShop=@specialistShop WHERE PrimiseID=@id", con);

             com.Parameters.Add("@id",SqlDbType.Int);
             com.Parameters["@id"].Value = Convert.ToInt32(premiseIn.PremiseId);

             com.Parameters.Add("@LocationName", SqlDbType.NVarChar, 255);
             com.Parameters["@LocationName"].Value = premiseIn.locationName;

             com.Parameters.Add("@AddressLine1", SqlDbType.NVarChar, 255);
             com.Parameters["@AddressLine1"].Value = premiseIn.address1;

             com.Parameters.Add("@PostCode", SqlDbType.NVarChar, 255);
             com.Parameters["@PostCode"].Value = premiseIn.postcode;

             com.Parameters.Add("@IsActive", SqlDbType.Bit);
             com.Parameters["@IsActive"].Value = premiseIn.isActive;

             com.Parameters.Add("@knowAs", SqlDbType.NVarChar, 255);
             com.Parameters["@knowAs"].Value = premiseIn.knowAs;

             com.Parameters.Add("@locationOrg", SqlDbType.NVarChar, 255);
             com.Parameters["@locationOrg"].Value = premiseIn.locationOrg;

             com.Parameters.Add("@locationStatus", SqlDbType.NVarChar, 255);
             com.Parameters["@locationStatus"].Value = premiseIn.locationStatus;

             com.Parameters.Add("@locationDate", SqlDbType.Date);
             com.Parameters["@locationDate"].Value = premiseIn.locationDate;

             com.Parameters.Add("@AddressLine2", SqlDbType.NVarChar, 255);
             com.Parameters["@AddressLine2"].Value = premiseIn.address2;

             com.Parameters.Add("@AddressLine3", SqlDbType.NVarChar, 255);
             com.Parameters["@AddressLine3"].Value = premiseIn.address3;

             com.Parameters.Add("@cityTown", SqlDbType.NVarChar, 255);
             com.Parameters["@cityTown"].Value = premiseIn.ctyTown;

             com.Parameters.Add("@country", SqlDbType.NVarChar, 255);
             com.Parameters["@country"].Value = premiseIn.country;

             com.Parameters.Add("@nationCoutry", SqlDbType.NVarChar, 255);
             com.Parameters["@nationCoutry"].Value = premiseIn.nationContry;

             com.Parameters.Add("@primaryLocation", SqlDbType.Bit);
             com.Parameters["@primaryLocation"].Value = premiseIn.primary;

             com.Parameters.Add("@locationMa", SqlDbType.Bit);
             com.Parameters["@locationMa"].Value = premiseIn.locationMa;

             com.Parameters.Add("@stNetCon", SqlDbType.Bit);
             com.Parameters["@stNetCon"].Value = premiseIn.stNetCon;

             com.Parameters.Add("@locationDes", SqlDbType.NVarChar, 255);
             com.Parameters["@locationDes"].Value = premiseIn.locatonDes;

             com.Parameters.Add("@phoneNum", SqlDbType.NVarChar, 255);
             com.Parameters["@phoneNum"].Value = premiseIn.phoneNum;

             com.Parameters.Add("@faxNum", SqlDbType.NVarChar, 255);
             com.Parameters["@faxNum"].Value = premiseIn.faxNum;

             com.Parameters.Add("@minNum", SqlDbType.NVarChar, 255);
             com.Parameters["@minNum"].Value = premiseIn.minNum;

             com.Parameters.Add("@isShop", SqlDbType.Bit);
             com.Parameters["@isShop"].Value = premiseIn.isShop;

             com.Parameters.Add("@shopDate", SqlDbType.Date);
             com.Parameters["@shopDate"].Value = premiseIn.shopDate;

             com.Parameters.Add("@specialistShop", SqlDbType.Bit);
             com.Parameters["@specialistShop"].Value = premiseIn.specialistDhop;
             return Convert.ToBoolean(com.ExecuteNonQuery());
        }
        public bool CheckLocationName(String name)
        {
            if (con.State == ConnectionState.Closed)
            {
                con.Open();
            }
            SqlCommand com = new SqlCommand("SELECT COUNT(*) FROM NewPremise WHERE LocationName = @name", con);             
            SqlDataAdapter sqlDa = new SqlDataAdapter(com);
            com.Parameters.AddWithValue("@name",name);
             
            int cout=(int)com.ExecuteScalar();
            return (cout>0);
        }
    }
}//#enNameSpace